<?php
// 当前预约信息
// header("content-type:text/html;charset=UTF-8");
include_once("conn.php");
include_once("u_getLoginInfo.php");
$sql_select = "SELECT * FROM order_infos JOIN department_infos ON order_infos.orderType = department_infos.department_ID WHERE user_ID = '" . $userID . "' ORDER BY orderDate ASC ";
$result = mysqli_query($connect_DB, $sql_select);
if ($result) {
    $num = mysqli_num_rows($result);
    if ($num == 0) {
        echo "
            <div class='main-content-orderinfo'>
                <div class='none-orderinfo'>
                    您暂时没有预约信息
                </div>
            </div>
        ";
    } else {
        while ($row_all = mysqli_fetch_object($result)) {
            // 查询宠物昵称
            $sql_petName = "SELECT * FROM pet_infos WHERE pet_ID = '" . $row_all->pet_ID . "'";
            $result_petName = mysqli_query($connect_DB, $sql_petName);
            $row_petName = mysqli_fetch_object($result_petName);
            // 查询医生信息
            $sql_docName = "SELECT * FROM doc_infos WHERE doc_ID = '" . $row_all->doc_ID . "'";
            $result_docName = mysqli_query($connect_DB, $sql_docName);
            $row_docName = mysqli_fetch_object($result_docName);
            echo "
            <div class='main-content-orderinfo'>
            <div class='main-content-orderinfo-left'>
                <img src='../public/pic/doc_imgs/" . $row_docName->doc_PhotoAddress . "'>
                <div class='orderdocinfo'><b>预约医生：</b><span>" . $row_docName->doc_Name . "</span></div>
            </div>
            <div class='main-content-orderinfo-right'>
                    <p><b>预约 ID：</b><span>" . $row_all->orderID . "</span></p>
                    <p><b>宠物昵称：</b><span>" . $row_petName->pet_Name . "</span></p>
                    <p><b>预约项目：</b><span>" . $row_all->orderType . " - ".$row_all->department_Name."</span></p>
                    <p><b>预约备注：</b><span class='remarkspan'>" . $row_all->orderRemark . "</span></p>
                    <p><b>申请日期：</b><span>" . $row_all->subDate . "&nbsp;&nbsp;" . $row_all->subTime . "</span></p>
                    <p><b>预约日期：</b><span>" . $row_all->orderDate . "&nbsp;&nbsp;" . $row_all->orderTime . "</span></p>
                    <p><b>联系电话：</b><span>" . $row_all->phone . "</span></p>";
            if ($row_all->orderState == 1) {
                echo "<p><b>预约状态：</b><span>已预约成功</span></p>
                        <a href='u_cancelOrder.php?orderID=" . $row_all->orderID . "'><button type='button' onclick='return cancelBtn();'>取消该预约</button></a>";
            } else {
                echo "<p><b>预约状态：</b><span>已提交取消申请</span></p>
                        <a href=''><button type='button' style='background-color: gray;' disabled>取消审核中</button></a>";
            }
            echo "</div>
            </div>
            ";
        }
    }
} else {
    echo "执行查询SQL错误：<br>" . $sql_select;
}

$connect_DB->close();
?>